$(document).ready(function() {
	queryResources("",pageNo,"");//默认查询
});

var pageSize = 5;
var pageNo = 0;

var queryResources = function(condition,pageNo,resCode){
	$("#jigou").hide();//影藏当前页面数据
	$("#loadingtable").show();//数据加载进度提示
	
	jQuery.post("/finance/resources//selResources.do",{pageSize:pageSize,pageNo:pageNo,resCode:resCode},function(str){
			$("#loadingtable").hide();//隐藏数据加载进度提示
			$("#jigou").show();//影藏当前页面数据
			//拼表头
			var htmltxtHead = "<caption>用户组信息</caption>"
								+'<thead>'
								+'<tr>'
								+'<th width="120">序号</th>'
								+'<th width="120">资源代码</th>'
								+'<th width="120">资源名称</th>'
								+'<th width="120">资源Url</th>'
								+'<th width="120">更新时间</th>'
								+'<th width="120">创建时间</th>'
								+'<th width="120">是否有效</th>'
								+'<th width="120">操作</th>'
								+'</tr>'
								+'</thead>'
			var htmltxtcontent = "";	
			var data = eval('(' + str + ')');
			htmltxtcontent += '<tbody>';
			if(data.data.length==0){
				htmltxtcontent += '<tr>'
				 				   +'<td width="120" colspan="8" align="center">对不起,没有您要查询的记录!</td>'
				 				   +'</tr>';
			}else{
				for (var i=0; i<data.data.length; i++) {
					htmltxtcontent += '<tr>'
				 				   +'<td width="120" align="center">'+ data.data[i].id +'</td>'
				 				   +'<td width="120" align="center">'+ data.data[i].ResourceCode +'</td>'
				 				   +'<td width="120" align="center">'+ data.data[i].ResourceName +'</th>'
				 				   +'<td width="120" align="center">'+ data.data[i].ResourceUrl +'</th>'
				 				   +'<td width="120">'+ data.data[i].updateTime +'</th>'
				 				   +'<td width="120">'+ data.data[i].createTime +'</th>'
				 				   +'<td width="120">'+ (data.data[i].isActive==1?"有效":"无效") +'</th>'
				 				   +'<td width="120"><div align="center">'
				 				  // +'<a href="#" target="">查看</a>|'
								   +'<a href="javascript:updateResource('+data.data[i].id+',\''+data.data[i].ResourceCode+'\');" target="_self">修改</a>|'
								   +'<a href="javascript:delResource('+data.data[i].id+');" target="">删除</a>'
				 				   +'</div></th>'
						         +'</tr>';
				}
			}

			htmltxtcontent += '</tbody>';
			 $("#jigou").html(htmltxtHead+htmltxtcontent);
			  //分页器
			if(data.totalPageCount > 1){
				$("#pagingToolDiv").show();
	            $("#pagingToolDiv").html(PagingToolV2.getPagingCode('bottomgo',condition, 'queryResources', data.totalPageCount,data.totalcount, pageNo));
            	$("#bottomgo").keydown(function(event){
                     if(event.keyCode==13){
                       if(parseInt($("#bottomgo").val())!=NaN){
                       	 if(data.totalPageCount<parseInt($("#bottomgo").val())){
                       	   parseInt($("#bottomgo").val(data.totalPageCount))
                       	 }
                         queryUsers('',parseInt($("#bottomgo").val()));
                       }
                     }
                });
            }else{
            	$("#pagingToolDiv").hide();
            }
        });
        
}

//模糊查询
function queryResource(){
	queryResources("",pageNo,$("#resCode").val());//模糊查询
}

//跳转到新增用户组页面
function toAddResourcePage(){
	window.open("/finance/views/console/addResource.jsp","_self");
}

//修改用户组
function updateResource(resId,resCode){
	window.open("/finance/views/console/addResource.jsp?resId="+resId+"&resCode=\""+resCode+"\"","_self");
}

//删除用户组
function delResource(id){
	if (confirm("确认删除?该操作会删除与该资源所有数据!!!")){
		jQuery.post("/finance/resources/delResource.do",{id:id},function(str){
			var data = eval('(' + str + ')');
			if(data.success){
				jAlert("删除资源成功!","提示");
				queryResources("",0,"");//刷新界面
			}else{
				jAlert("删除资源失败!","提示");			
			}
	    });
	}
}


